var intersection = function(nums1 ,nums2){
  const result = new Set();
  const set = new Set(nums2);
  for(num of nums1){
    if(set.has(num)){
      result.add(num)
    }
  }
  return Array.from(result);
}
console.log(intersection([1,2],[2,3,4]));